// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   DebuggingClassWriter.java

package org.springframework.cglib.core;

import java.io.*;
import java.lang.reflect.Constructor;
import java.security.AccessController;
import java.security.PrivilegedAction;
import org.springframework.asm.*;

// Referenced classes of package org.springframework.cglib.core:
//			CodeGenerationException

public class DebuggingClassWriter extends ClassVisitor
{

	public static final String DEBUG_LOCATION_PROPERTY = "cglib.debugLocation";
	private static String debugLocation;
	private static Constructor traceCtor;
	private String className;
	private String superName;

	public DebuggingClassWriter(int flags)
	{
		super(0x40000, new ClassWriter(flags));
	}

	public void visit(int version, int access, String name, String signature, String superName, String interfaces[])
	{
		className = name.replace('/', '.');
		this.superName = superName.replace('/', '.');
		super.visit(version, access, name, signature, superName, interfaces);
	}

	public String getClassName()
	{
		return className;
	}

	public String getSuperName()
	{
		return superName;
	}

	public byte[] toByteArray()
	{
		return (byte[])(byte[])AccessController.doPrivileged(new PrivilegedAction() {

			public Object run()
			{
				byte b[];
				String dirs;
				b = ((ClassWriter)).toByteArray();
				if (DebuggingClassWriter.debugLocation == null)
					break MISSING_BLOCK_LABEL_310;
				dirs = className.replace('.', File.separatorChar);
				OutputStream out;
				(new File(DebuggingClassWriter.debugLocation + File.separatorChar + dirs)).getParentFile().mkdirs();
				File file = new File(new File(DebuggingClassWriter.debugLocation), dirs + ".class");
				out = new BufferedOutputStream(new FileOutputStream(file));
				out.write(b);
				out.close();
				break MISSING_BLOCK_LABEL_154;
				Exception exception;
				exception;
				out.close();
				throw exception;
				if (DebuggingClassWriter.traceCtor == null)
					break MISSING_BLOCK_LABEL_310;
				File file = new File(new File(DebuggingClassWriter.debugLocation), dirs + ".asm");
				out = new BufferedOutputStream(new FileOutputStream(file));
				ClassReader cr = new ClassReader(b);
				PrintWriter pw = new PrintWriter(new OutputStreamWriter(out));
				ClassVisitor tcv = (ClassVisitor)DebuggingClassWriter.traceCtor.newInstance(new Object[] {
					null, pw
				});
				cr.accept(tcv, 0);
				pw.flush();
				out.close();
				break MISSING_BLOCK_LABEL_310;
				Exception exception1;
				exception1;
				out.close();
				throw exception1;
				Exception e;
				e;
				throw new CodeGenerationException(e);
				return b;
			}

		});
	}

	static Class class$(String x0)
	{
		return Class.forName(x0);
		ClassNotFoundException x1;
		x1;
		throw new NoClassDefFoundError(x1.getMessage());
	}

	static 
	{
		debugLocation = System.getProperty("cglib.debugLocation");
		if (debugLocation != null)
		{
			System.err.println("CGLIB debugging enabled, writing to '" + debugLocation + "'");
			try
			{
				Class clazz = Class.forName("org.springframework.asm.util.TraceClassVisitor");
				traceCtor = clazz.getConstructor(new Class[] {
					org.springframework.asm.ClassVisitor.class, java.io.PrintWriter.class
				});
			}
			catch (Throwable ignore) { }
		}
	}




}
